package com.kha.listone.util;

import java.util.Calendar;
import java.util.Date;

public class DateFormatter {

	public static final String[] MONTH_NAMES = { "January", "February",
			"March", "April", "May", "June", "July", "August", "September",
			"October", "November", "December" };

	public static final int TYPE_1 = 0;
	public static final int TYPE_2 = 1;
	public static final int TYPE_3 = 2;

	public static String format(Date myDate, int type) {

		Calendar calendar = Calendar.getInstance();

		calendar.setTime(myDate);

		int day = calendar.get(Calendar.DAY_OF_MONTH);
		int monthNumber = calendar.get(Calendar.MONTH);

		String month = MONTH_NAMES[monthNumber];

		int year = calendar.get(Calendar.YEAR);

		int hour = calendar.get(Calendar.HOUR);
		int minute = calendar.get(Calendar.MINUTE);
		String H, M;
		if (hour < 10) {
			H = "0" + String.valueOf(hour);
		} else {
			H = String.valueOf(hour);
		}
		if (minute < 10) {
			M = "0" + String.valueOf(minute);
		} else {
			M = String.valueOf(minute);
		}
		String amPm = calendar.get(Calendar.AM_PM) == 1 ? " am" : " pm";
		if (type == TYPE_2) {
			return (day + "/" + monthNumber + "/" + year + " " + H + ":"
					+ M + amPm);
		} else if (type == TYPE_1) {
			return (monthNumber + "/" + day + "/" + year + " " + H + ":"
					+ M + amPm);
		} else {
			return (month.substring(0, 2) + "-" + day + ", " + year + " "
					+ H + ":" + M + amPm);
		}
	}
}
